package com.five.calendar.database.bean;

import android.content.ContentValues;
import android.database.Cursor;

import com.five.calendar.common.database.IDatabaseObject;
import com.five.calendar.database.table.ScheduleTable;

import java.io.Serializable;

/**
 * Created by xin on 2017/8/29.
 */

public class ScheduleBean implements IDatabaseObject, Serializable{

    public long id;
    //日程创建时间
    public long createTime;
    //日程事件标题
    public String title;
    //地址
    public String address;
    //日程事件开始时间
    public long startTime;
    //日程事件结束时间
    public long endTime;
    //日程事件重要性
    public int importance;
    //备注
    public String note;
    //是否提醒
    public int isRemind;
    //提前多长时间提醒
    public long remindTime;

    public ScheduleBean(){

    }

    public ScheduleBean(String title, String address, long startTime, long endTime, int importance, String note, int isRemind, long remindTime){
        this.title = title;
        this.address = address;
        this.startTime = startTime;
        this.endTime = endTime;
        this.importance = importance;
        this.note = note;
        this.isRemind = isRemind;
        this.remindTime = remindTime;
    }

    @Override
    public void writeObject(ContentValues values, String table) {
        if (ScheduleTable.TABLE_NAME.equals(table)){
            values.put(ScheduleTable.TITLE, title);
            values.put(ScheduleTable.CREATETIME, createTime);
            values.put(ScheduleTable.ADDRESS, address);
            values.put(ScheduleTable.STARTTIME, startTime);
            values.put(ScheduleTable.ENDTIME, endTime);
            values.put(ScheduleTable.IMPORTANCE, importance);
            values.put(ScheduleTable.NOTE, note);
            values.put(ScheduleTable.ISREMIND, isRemind);
            values.put(ScheduleTable.REMINDTIME, remindTime);
        }
    }

    @Override
    public void readObject(Cursor cursor, String table) {
        if(ScheduleTable.TABLE_NAME.equals(table)){
            id = cursor.getLong(cursor.getColumnIndex(ScheduleTable.ID));
            title = cursor.getString(cursor.getColumnIndex(ScheduleTable.TITLE));
            address = cursor.getString(cursor.getColumnIndex(ScheduleTable.ADDRESS));
            createTime = cursor.getLong(cursor.getColumnIndex(ScheduleTable.CREATETIME));
            startTime = cursor.getLong(cursor.getColumnIndex(ScheduleTable.STARTTIME));
            endTime = cursor.getLong(cursor.getColumnIndex(ScheduleTable.ENDTIME));
            importance = cursor.getInt(cursor.getColumnIndex(ScheduleTable.IMPORTANCE));
            note = cursor.getString(cursor.getColumnIndex(ScheduleTable.NOTE));
            isRemind = cursor.getInt(cursor.getColumnIndex(ScheduleTable.ISREMIND));
            remindTime = cursor.getLong(cursor.getColumnIndex(ScheduleTable.REMINDTIME));
        }
    }

    @Override
    public String toString() {
        return title + createTime + startTime + endTime + importance + note;
    }
}
